home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 310 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  89 lines

  1. Path: aed.aed-graphics.de!news
  2. From: Joerg Leinhoss <Leinhoss@AED-Graphics.DE>
  3. Newsgroups: comp.lang.c++
  4. Subject: g++2.7.2 bug
  5. Date: Wed, 03 Jan 1996 17:44:35 +0100
  6. Organization: AED Graphics GmbH
  7. Message-ID: <30EAB273.41C6@AED-Graphics.DE>
  8. NNTP-Posting-Host: aed21.aed-graphics.de
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b3 (X11; I; OSF1 V3.2 alpha)
  13. CC: leinhoss
  14.  
  15. Hi World,
  16. Which g++ version remove the following bug: 
  17.  
  18. test.cc:
  19.  
  20. #include <stdio.h>
  21.  
  22. int table[2][2][2] = {{{2,5}, {4,5}}, {{3,8}, {2,6}}};
  23.  
  24. // #define output(i,j,k) printf("%d%d%d",i,j,k);
  25. #define output(i,j,k) printf("%d",table[i][j][k])
  26.  
  27. void
  28. a() {
  29.   for(int i=0; i<2; i++)
  30.     output(i,0,0);
  31.   for(i=0; i<2; i++)
  32.     for(int j=0; j<2; j++)
  33.       output(i,j,0);
  34.   for(i=0; i<2; i++)
  35.     for(int j=0; j<2; j++)
  36.       for(int k=0; k<2; k++)
  37.       output(i,j,k);
  38. }
  39.  
  40.  
  41. void
  42. b() {
  43.   int i,j,k;
  44.   for(i=0; i<2; i++)
  45.     output(i,0,0);
  46.   for(i=0; i<2; i++)
  47.     for(j=0; j<2; j++)
  48.       output(i,j,0);
  49.   for(i=0; i<2; i++)
  50.     for(j=0; j<2; j++)
  51.       for(k=0; k<2; k++)
  52.       output(i,j,k);
  53. }
  54.  
  55. void
  56. main() {
  57.   a(); putchar('\n');
  58.   b(); putchar('\n');
  59. }
  60.  
  61. //eof
  62.  
  63. The functions a and b differs only in the function global declaration of i, j
  64. and k. One macro version makes a simple function call, the other make a array
  65. access with i, j and k. Both functions should produce the same result with both
  66. output macros!
  67.  
  68. While compiling g++2.7.2 warns:
  69. test.cc: In function `void a()':
  70. test.cc:12: warning: name lookup of `i' changed for new ANSI `for' scoping
  71. test.cc:10: warning:   using obsolete binding at `i'
  72.  
  73. Ok, I know what this means. No Comment.
  74.  
  75. The output compiled with the first output-define is
  76. 000100000010100110000001010011100101110111
  77. 000100000010100110000001010011100101110111
  78. ... all correct.
  79.  
  80. But the output compiled with the second-define is
  81. 23222526
  82. 23243225453826
  83. ... the bug !?
  84.  
  85. Which option can prevent this bug ? Which g++ version removes it ?
  86.  
  87. Joerg Leinhoss
  88. (Please no emails, post the replys to this newsgroups)
  89.